using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using XPanderControl;


namespace TaskVision.Components
{
    [Designer(typeof(GradiantPanelDesigner)), DesignTimeVisibleAttribute(true)]
    public partial class GradiantPanel : System.Windows.Forms.Panel
    {

        //Required by the Windows Form Designer
        private System.ComponentModel.IContainer components = null;

        private Color m_SecendColor = Color.FromArgb(33, 93, 198);
        private Color m_FirstColor = Color.FromArgb(198, 210, 248);
        //private Color AnotherGoodColor = Color.FromArgb(66,142,255);

        private LinearGradientMode m_GradientMode = LinearGradientMode.Horizontal;

        public GradiantPanel()
        {
            InitializeComponent();
            //'Add any initialization after the InitializeComponent() call
            //' We draw everything, and repaint when resized.
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.ContainerControl, true);

            this.BackColor = Color.FromArgb(214, 223, 247); //' Default

        }

        private void GradiantPanel_Load(object sender, EventArgs e)
        {

        }


        #region Public Properties

        [Description("First color."), DefaultValue("180,190,240"), Category("Appearance")]
        public Color FirstColor
        {
            get { return m_FirstColor; }
            set
            {
                m_FirstColor = (Color)value;
                this.Invalidate();
            }
        }

        [Description("Gradient Mode"), DefaultValue(LinearGradientMode.Horizontal), Category("Appearance")]
        public LinearGradientMode GradientMode
        {
            get { return m_GradientMode; }
            set
            {
                m_GradientMode = value;
                this.Invalidate();
            }
        }

        [Description("Secend color"), DefaultValue("33,93,198"), Category("Appearance")]
        public Color SecendColor
        {
            get { return m_SecendColor; }
            set
            {
                m_SecendColor = (Color)value;
                this.Invalidate();
            }
        }

        #endregion

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            Rectangle rc = new Rectangle(0, 0, this.Width, this.Height);
            LinearGradientBrush b = new LinearGradientBrush(rc, SecendColor, FirstColor, m_GradientMode);

            //' Now draw the caption areas with the rounded corners at the top
            e.Graphics.FillRectangle(b, rc);
            //base.OnPaintBackground(e);
        }
    }

    public class GradiantPanelDesigner : ParentControlDesigner
    {
        private Pen m_BorderPen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark));
        private GradiantPanel m_Control;

        public GradiantPanelDesigner()
        {
            m_BorderPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        }

        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);
            m_Control = this.Control as GradiantPanel;
        }

        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);
            pe.Graphics.DrawRectangle(m_BorderPen, 0, 0, m_Control.Width - 2, m_Control.Height - 2);
        }
    }
}



    